home *** CD-ROM | disk | FTP | other *** search
- // ******************************************************************
- // program written by
- // Paul Baxter
- // MacHack'98
- //
- //
- // ******************************************************************
-
- #include <A4Stuff.h>
- #include <StdLib.h>
-
- #include "patch.h"
- #include "animate.h"
-
- //#include "debug.h"
-
-
- // Semi- Automagic macros for generic Fat patches
- #define PatchTrap _HideWindow
-
- #define PatchUPPProcInfo ThePatchuppProcInfo
- #define PatchUPPProcPtr ThePatchProcPtr
- #define PatchFun ThePatch
-
- #ifdef powerc
- enum {
- PatchUPPProcInfo = kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(kNoByteCode))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))
- };
- typedef UniversalProcPtr PatchUPP;
-
- #define NEW_PROC(proc) (PatchUPP) \
- NewRoutineDescriptor((ProcPtr)(proc), PatchUPPProcInfo, GetCurrentArchitecture())
-
- #define NEW_68KPROC(proc) (PatchUPP) \
- NewRoutineDescriptor((ProcPtr)(proc), PatchUPPProcInfo, kM68kISA);
-
- #define NEW_FATPROC(proc68K, procPPC) (PatchUPP) \
- NewFatRoutineDescriptor((ProcPtr)(proc68K), (ProcPtr)(procPPC), PatchUPPProcInfo)
-
- #define CALL_PROC(proc, p1) \
- CallUniversalProc((UniversalProcPtr) (proc) , PatchUPPProcInfo, p1)
- #else
- enum {
- PatchUPPProcInfo = 0
- };
- typedef pascal void (*PatchUPPProcPtr)(WindowPtr);
- typedef PatchUPPProcPtr PatchUPP;
- #define NEW_PROC(proc) (PatchUPP)(proc)
- #define CALL_PROC(proc,p1) (* (PatchUPPProcPtr) (proc))(p1)
- #endif
-
- // Function Prototypes
- pascal ProcPtr main(PlaySoundUPP soundPlayer68K, PlaySoundUPP soundPlayerPPC, short rID, short install);
- pascal void PatchFun(WindowPtr theWindow);
-
- // Globals
- PlaySoundUPP gSoundPlayer = nil;
- PatchUPP gOriginal = nil;
-
- #ifdef powerc
- // for Metrowerks' linker, this defines the interface for main().
- ProcInfoType __procinfo = PatchInstallerUPPProcInfo;
- #endif
-
-
- // * ******************************************************************************
- // * main
- // * Entry point for the HideWindow Patch Installer
- // * ******************************************************************************
- pascal ProcPtr main(PlaySoundUPP soundPlayer68K, PlaySoundUPP soundPlayerPPC, short rID, short install)
- {
- #ifndef powerc
- #pragma unused(soundPlayerPPC, rID)
- #else
- Handle theHandle;
- ProcPtr the68KProc;
- PatchInstallerUPP patchInstaller68K;
- #endif
-
- PatchUPP Patch;
- THz theZone;
- ProcPtr theProc;
-
- EnterCodeResource();
-
- theZone = GetZone();
- SetZone(SystemZone());
-
- // DEBUG("Enter HideWindowPatch Installer");
-
- Patch = nil;
- theProc = (ProcPtr)PatchFun;
- gSoundPlayer = soundPlayer68K;
- gOriginal = (PatchUPP)
- NGetTrapAddress(PatchTrap, (PatchTrap & 0x0800) ? ToolTrap : OSTrap);
-
- #ifdef powerc
- if (soundPlayerPPC)
- gSoundPlayer = soundPlayerPPC;
- else
- if (gSoundPlayer->goMixedModeTrap != _MixedModeMagic)
- gSoundPlayer = NEW_68KPLAYSOUNDPROC(gSoundPlayer);
-
- if (gOriginal->goMixedModeTrap != _MixedModeMagic)
- gOriginal = NEW_68KPROC(gOriginal);
- #endif
-
- if (!install) {
- // DEBUG("Exit HideWindowPatch Installer (no Install)");
-
- SetZone(theZone);
- ExitCodeResource();
- return theProc;
- }
-
- #ifdef powerc
- theHandle = GetResource(kPatchType68K, rID);
- if (theHandle) {
-
- LoadResource(theHandle);
- HLockHi(theHandle);
- DetachResource(theHandle);
-
- the68KProc = 0;
- patchInstaller68K = NEW_68K_PATCH_INSTALLER_PROC(*theHandle);
- the68KProc = (ProcPtr) CALL_PATCH_INSTALLER_PROC(patchInstaller68K, soundPlayer68K, soundPlayerPPC, rID, false);
- DisposeRoutineDescriptor(patchInstaller68K);
-
- if (the68KProc)
- Patch = NEW_FATPROC(the68KProc, theProc);
- }
- #endif
-
- if (!Patch)
- Patch = NEW_PROC(theProc);
-
- NSetTrapAddress((UniversalProcPtr) Patch, PatchTrap, (PatchTrap & 0x0800) ? ToolTrap : OSTrap);
-
- SetZone(theZone);
-
- // DEBUG("Exit HideWindowPatch Installer");
-
- ExitCodeResource();
- return theProc;
- }
-
- // * ******************************************************************************
- // * ThePatch
- // * HideWindow Patch Entry Point
- // * ******************************************************************************
- pascal void PatchFun(WindowPtr theWindow)
- {
- Point savePt;
- long saveRefCon;
-
- EnterCodeResource();
-
- saveRefCon = ((WindowPeek)theWindow)->refCon;
- if (((WindowPeek)theWindow)->refCon != kPatchSigniture) {
-
- ((WindowPeek)theWindow)->refCon = kPatchSigniture;
- if (gSoundPlayer) {
- CALL_SOUNDPROC(gSoundPlayer);
- }
- if (((WindowPeek)theWindow)->visible) {
- AnimateWindow(theWindow, &savePt);
- }
- }
-
- CALL_PROC(gOriginal, theWindow);
-
- ((WindowPeek)theWindow)->refCon = saveRefCon;
- ExitCodeResource();
- }
-
-